package com.service.business.order.controller;

import com.service.business.framework.log.RequestLog;
import com.service.business.member.service.MemberMiningOrderService;
import com.service.business.order.controller.rep.*;
import com.service.business.order.controller.req.OrderComboPageReq;
import com.service.business.order.controller.req.OrderReq;
import com.service.business.order.controller.req.RenewOrderReq;
import com.service.business.order.service.OrderProductHrComboService;
import com.service.core.rest.BaseController;
import com.service.core.rest.request.PageRequest;
import com.service.core.rest.response.BaseResponse;
import com.service.core.rest.response.OneResponse;
import com.service.core.rest.response.PageResponse;
import com.service.dao.dto.OrderMemberRank;
import com.service.dao.model.MemberMiningOrder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * <dl>
 * <dt>back-end</dt>
 * <dd>Description:</dd>
 * <dd>Copyright: Copyright (C) 2015</dd>
 * <dd>Company: </dd>
 * <dd>CreateDate: 2019年11月12日</dd>
 * </dl>
 *
 * @author
 */
@Slf4j
@RestController()
@RequestMapping("order-product-hr-combo")
@Api(tags = "算力套餐订单")
public class OrderProductHrComboController extends BaseController {

	@Autowired
	private OrderProductHrComboService productHrComboService;
	@Autowired
	private MemberMiningOrderService miningOrderService;

	@ApiOperation("立即下单:算力套餐")
	@RequestLog("立即下单:算力套餐")
	@PostMapping("order/{comboId}")
	public OneResponse<BaseOrderRep> orderCombo(@PathVariable("comboId") Integer comboId, @RequestBody @Validated OrderReq orderReq) {
		orderReq.setId(comboId);
		return successQueryOneResponse(productHrComboService.orderHashRateCombo(orderReq));
	}

	@ApiOperation("支付详情")
	@RequestLog("支付详情")
	@PostMapping("pay-detail/{orderNo}")
	public OneResponse<BaseOrderRep> payInfo(@PathVariable("orderNo") String orderNo) {
		return successQueryOneResponse(productHrComboService.getOrderPayInfo(orderNo));
	}

	@ApiOperation("订单分页:算力套餐")
	@RequestLog("订单分页:算力套餐")
	@PostMapping("list/{orderStatus}")
	public PageResponse<OrderHrComboPageRep> orderList(@PathVariable("orderStatus") Integer orderStatus, @RequestBody OrderComboPageReq request) {
		request.setOrderStatus(orderStatus);
		return successQueryPageResponse(productHrComboService.page(request));
	}

	@ApiOperation("订单详情:算力套餐")
	@RequestLog("订单详情:算力套餐")
	@GetMapping("detail/{orderNo}")
	public OneResponse<OrderHrComboDetailRep> orderList(@PathVariable("orderNo") String orderNo) {
		return successQueryOneResponse(productHrComboService.getOrderDetail(orderNo));
	}

	@RequestLog("取消订单")
	@ApiOperation("取消订单")
	@PostMapping("cancel/{orderNo}")
	public BaseResponse cancelOrder(@ApiParam @PathVariable("orderNo") String orderNo) {
		productHrComboService.cancelOrder(orderNo);
		return successBaseResponse();
	}

	@RequestLog("续约订单")
	@ApiOperation("续约订单")
	@PostMapping("renew/{orderNo}")
	public BaseResponse renew(@PathVariable("orderNo") String orderNo, @RequestBody RenewOrderReq renewReq) {
		productHrComboService.renewOrder(orderNo, renewReq);
		return successBaseResponse();
	}

	@ApiOperation("订单详情:收益明细")
	@RequestLog("订单详情:收益明细")
	@GetMapping("reward-order/{orderId}")
	public OneResponse<OrderRewardDetailsRep> orderRewardList(@PathVariable("orderId") Integer orderId) {
		return successQueryOneResponse(productHrComboService.getOrderRewardDetail(orderId));
	}


	@RequestLog("线性释放记录列表")
	@ApiOperation("线性释放记录列表")
	@PostMapping("mining-order/{coinsName}")
	public PageResponse<MemberMiningOrder> pageMemberMiningRelease(@PathVariable("coinsName") String coinsName, @ApiParam @RequestBody @Validated PageRequest request) {
		return successQueryPageResponse(miningOrderService.pageByMemberIdAndCoins(request, coinsName));
	}

	@ApiOperation("我的总算力")
	@RequestLog("我的总算力")
	@PostMapping("total-hash-rate/{coinsName}")
	public OneResponse<MyHashRateTotalRep> totalHashRate(@PathVariable("coinsName") String coinsName) {
		return successQueryOneResponse(productHrComboService.totalHashRate(coinsName));
	}

	@ApiOperation("我的总算力统计详情")
	@RequestLog("我的总算力统计详情")
	@PostMapping("total-hash-rate-details/{coinsName}")
	public OneResponse<TotalMyHashRateRep> totalHashRateDetails(@PathVariable("coinsName") String coinsName) {
		return successQueryOneResponse(productHrComboService.totalHashRateDetails(coinsName));
	}

	@ApiOperation("我的订单统计")
	@RequestLog("我的订单统计")
	@PostMapping("hr-order-hash-rate/{coinsName}")
	public OneResponse<MyOrderHashRateRep> hrOrderHashRate(@PathVariable("coinsName") String coinsName) {
		return successQueryOneResponse(productHrComboService.totalMyOrderHashRateByCoin(coinsName));
	}

	@ApiOperation("订单统计排行")
	@RequestLog("订单统计排行")
	@PostMapping("hr-order-hash-rate-rank/{coinsName}")
	public OneResponse<OrderMemberRank> totalOrderRanking(@PathVariable("coinsName") String coinsName) {
		Date currentMonth = new Date();
		return successQueryOneResponse(productHrComboService.totalRankByPayMoneyAndSomeMonth(coinsName, currentMonth));
	}
}
